/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

/**
 * Created by yfyang on 4/12/14.
 */
define([ 'adminapp'], function ($app) {
    // nav menu
    $app.navactive('format');

    var action_tpl = Handlebars.compile($(g.actiontpl).html());
    var rank_tpl = Handlebars.compile($(g.ranktpl).html());

    $app.listtable({
        'sAjaxSource' : g.ctx + "admin/format/list",
        'aoColumns'   : [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'id' },
            {'mDataProp': 'name' },
            {'mDataProp': 'rank' },
            {'mDataProp': 'description' },
            {'mDataProp': 'categorys' },
            {'mDataProp': 'parent' }
        ],
        'aoColumnDefs': [
            { 'bSearchable': false, 'bVisible': false, 'aTargets': [ 2 ] },
            { 'bSearchable': false, 'bVisible': false, 'aTargets': [ 6 ] },
            { 'bSearchable': false, 'bVisible': false, 'aTargets': [ 7 ] },
            {
                'aTargets': [4],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    var tpl_data = {};
                    var rank = full.rank;
                    if (rank) {
                        switch (rank) {
                            case 1:
                                tpl_data['color'] = 'label-success';
                                tpl_data['rankname'] = '一级';
                                break;
                            case 2:
                                tpl_data['color'] = 'label-primary';
                                tpl_data['rankname'] = '二级';
                                break;
                            case 3:
                                tpl_data['color'] = 'label-info';
                                tpl_data['rankname'] = '三级';
                                break;
                            default:
                                tpl_data['color'] = 'label-default';
                                tpl_data['rankname'] = rank + '级';
                                break;
                        }
                    }
                    return rank_tpl(tpl_data);
                }
            },
            {
                'aTargets': [8],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return action_tpl(full);
                }
            }
        ]
    }, 'format-list');
    return {};
});